var t = getApp();

Page({
    data: {
        show: "",
        company: {},
        person: {},
        timer: null,
        flow_id: "",
        face_flow_id: ""
    },
    onLoad: function(t) {
        var a = t.show;
        this.setNavigationBar(a), this.setData({
            show: a
        }), this.data.timer && clearInterval(this.data.timer), "company" === a ? this.getCompanyData() : 1 == t.auth_company ? this.setData({
            person: {
                status: "SUCCESSFUL"
            }
        }) : this.checkPerson();
    },
    setNavigationBar: function(t) {
        "person" == t ? wx.setNavigationBarTitle({
            title: "个人认证结果"
        }) : wx.setNavigationBarTitle({
            title: "企业认证结果"
        });
    },
    toSign: function(t) {
        var a = "", e = "", s = t.target.dataset;
        s.str && (a = s.str), e = 1 == a ? "/packageH/signIndexPlu/signCompany/signCompany" : "home" == a ? "/packageH/signIndexPlu/contractList/contractList" : "/packageH/signIndexPlu/personBank/personBank", 
        wx.redirectTo({
            url: e
        });
    },
    checkPerson: function() {
        var a = this, e = this, s = t.getNetAddresss("plugin.shop-esign.frontend.person.get-person-info");
        t._getNetWork({
            url: s,
            success: function(s) {
                var n = s.data;
                1 === n.result && n.data.info ? 1 == n.data.info.status ? e.setData({
                    person: {
                        status: "SUCCESS"
                    }
                }) : 1 == n.data.info.has_face ? (a.data.face_flow_id = n.data.info.face_flow_id, 
                a.data.flow_id = n.data.info.flow_id, a.checkResult()) : a.getPersonData() : (e.setData({
                    person: {
                        status: "FAIL"
                    }
                }), t.tips(n.msg));
            }
        });
    },
    checkResult: function() {
        var a = this, e = t.getNetAddresss("plugin.shop-esign.frontend.person.auth-face-result");
        t._postNetWork({
            url: e,
            data: {
                flow_id: this.data.flow_id,
                face_flow_id: this.data.face_flow_id
            },
            success: function(t) {
                var e = t.data;
                1 === e.result ? a.setData({
                    person: e.data
                }) : a.setData({
                    person: {
                        status: "FAIL"
                    }
                });
            }
        });
    },
    getPersonData: function() {
        var a = this, e = t.getNetAddresss("plugin.shop-esign.frontend.person.check-person-approve");
        t._getNetWork({
            url: e,
            success: function(e) {
                var s = e.data;
                1 === s.result ? (a.setData({
                    person: s.data
                }), "99" == s.data.status_code ? a.setData({
                    person: {
                        status: "SUCCESS"
                    }
                }) : a.setData({
                    person: {
                        status: "FAIL"
                    }
                })) : t.tips(s.msg);
            }
        });
    },
    getCompanyData: function() {
        var a = this, e = t.getNetAddresss("plugin.shop-esign.frontend.company.check-company-approve");
        t._getNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                1 === e.result && (a.setData({
                    company: e.data,
                    status: e.data.status_code
                }), "1" == a.data.status ? a.data.timer || (a.data.timer = setInterval(function() {
                    a.getCompanyData();
                }, 3e4)) : (a.data.timer && clearInterval(a.data.timer), setTimeout(function() {
                    wx.redirectTo({
                        url: "/packageH/signIndexPlu/contractList/contractList"
                    });
                }, 3e3)));
            },
            fial: function(t) {
                console.log(t, "-------err--------");
            }
        });
    },
    freeTell: function() {
        wx.makePhoneCall({
            phoneNumber: "0755-66635068"
        });
    }
});